package sliver.dao.impl;

import java.io.Serializable;
import java.util.List;

import org.springframework.stereotype.Repository;

import sliver.dao.VipDao;
import sliver.entity.Vip;

@Repository
public class VipDaoImpl extends BaseDaoImpl<Vip> implements VipDao{

	@Override
	public Vip getLevel1(Serializable shopperId) {
		
		String queryString = "SELECT vip " +
							 "FROM Vip vip " +
							 "WHERE vip.vipLevel = 1 " +
							 "AND vip.shopper.id = ?";
		
		List<Vip> vips = complexQuery(queryString, new Object[]{shopperId});
		
		if(vips != null && vips.size() > 0)
			return vips.get(0);
		
		return null;
	}

	@Override
	public List<Vip> listVipLevels(Serializable shopperId) {
		
		String queryString = "SELECT vip " +
				 			 "FROM Vip vip " +
				 			 "WHERE vip.shopper.id = ? " +
				 			 "ORDER BY vip.vipLevel ASC";
		
		return complexQuery(queryString, new Object[]{shopperId});
	}
}
